package com.irdstudio.efp.cus.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.cus.service.dao.GjjReturnInfoTempDao;
import com.irdstudio.efp.cus.service.domain.GjjReturnInfoTemp;
import com.irdstudio.efp.cus.service.facade.GjjReturnInfoTempService;
import com.irdstudio.efp.cus.service.vo.GjjReturnInfoTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 公积金返回信息临时表服务实现
 *
 * @author gcb
 * @date 2020-08-12
 */
@Service("gjjReturnInfoTempService")
public class GjjReturnInfoTempServiceImpl implements GjjReturnInfoTempService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(GjjReturnInfoTempServiceImpl.class);

    @Autowired
    private GjjReturnInfoTempDao gjjReturnInfoTempDao;

    /**
     * 新增数据
     *
     * @param gjjReturnInfoTempVo
     * @return
     */
    @Override
    public int insert(GjjReturnInfoTempVO gjjReturnInfoTempVo) {
        logger.debug("当前新增数据为:" + gjjReturnInfoTempVo.toString());
        int num = 0;
        try {
            GjjReturnInfoTemp gjjReturnInfoTemp = new GjjReturnInfoTemp();
            beanCopy(gjjReturnInfoTempVo, gjjReturnInfoTemp);
            num = gjjReturnInfoTempDao.insert(gjjReturnInfoTemp);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param gjjReturnInfoTempVo
     * @return
     */
    @Override
    public int deleteByPk() {
        logger.debug("当前删除数据条件为:");
        int num = 0;
        try {
            GjjReturnInfoTemp gjjReturnInfoTemp = new GjjReturnInfoTemp();
            num = gjjReturnInfoTempDao.deleteByPk(gjjReturnInfoTemp);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param gjjReturnInfoTempVo
     * @return
     */
    @Override
    public int updateByPk(GjjReturnInfoTempVO gjjReturnInfoTempVo) {
        logger.debug("当前修改数据为:" + gjjReturnInfoTempVo.toString());
        int num = 0;
        try {
            GjjReturnInfoTemp gjjReturnInfoTemp = new GjjReturnInfoTemp();
            beanCopy(gjjReturnInfoTempVo, gjjReturnInfoTemp);
            num = gjjReturnInfoTempDao.updateByPk(gjjReturnInfoTemp);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + gjjReturnInfoTempVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inGjjReturnInfoTempVo
     * @return
     */
    @Override
    public GjjReturnInfoTempVO queryByPk(GjjReturnInfoTempVO inGjjReturnInfoTempVo) {
        logger.debug("当前查询参数信息为:" + inGjjReturnInfoTempVo);
        try {
            GjjReturnInfoTemp queryGjjReturnInfoTemp = new GjjReturnInfoTemp();
            beanCopy(inGjjReturnInfoTempVo, queryGjjReturnInfoTemp);
            GjjReturnInfoTemp queryRslGjjReturnInfoTemp = gjjReturnInfoTempDao.queryByPk(queryGjjReturnInfoTemp);
            if (Objects.nonNull(queryRslGjjReturnInfoTemp)) {
                return beanCopy(queryRslGjjReturnInfoTemp, new GjjReturnInfoTempVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int batchInsert(List<GjjReturnInfoTempVO> list){
        logger.info("批量插入数据开始，数据信息为：" + list.toString());
        try {
            List<GjjReturnInfoTemp> temps = (List<GjjReturnInfoTemp>)beansCopy(list,GjjReturnInfoTemp.class);
            int num = gjjReturnInfoTempDao.batchInsert(temps);
            return num;
        } catch (Exception e) {
            logger.error("批量插入数据失败！");
        }
        return 0;
    }

}
